package com.faceye.test.util;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.*;

/**
 * @Description:
 * @Author:haipenge
 * @Date:2020-05-29 15:11
 * @Version:1.0
 **/
@RunWith(JUnit4.class)
public class SetTestCase {
    private Logger logger= LoggerFactory.getLogger(SetTestCase.class);
    private Set<String> set =null;
    private Map<String,String> map =null;
    private List<String> list=null;
    @Before
    public void setUp() throws Exception{
        set =new HashSet<String>();
        long start=System.currentTimeMillis();
        for(int i=0;i<10000;i++){
            set.add("Key-"+i);
        }
        long end = System.currentTimeMillis();
        logger.debug(">>FaceYe set init 1000 cost :{}",end-start);

        start=System.currentTimeMillis();
        map=new HashMap<String,String>();

        for(int i=0;i<10000;i++){
        map.put("Key-"+i,""+i);
        }
        end = System.currentTimeMillis();
        logger.debug(">>FaceYe map init 10000 cost :{}",end-start);
        list=new ArrayList<String>();

    }

    @Test
    public void  testSet(){
        long start =System.currentTimeMillis();
        boolean res=set.contains("Key-1000");
        long end =System.currentTimeMillis();
        logger.debug(">>FaceYe test set contains cost:{}",end-start);
    }

    @Test
    public void testMap(){
        long start= System.currentTimeMillis();
        String  v = map.get("Key-100");
        long end = System.currentTimeMillis();
        logger.debug(">>FaceYe test map contains cost:{}",end-start);
    }

    @Test
    public void testList(){
        int size =0;
        long start=System.currentTimeMillis();
        size =10000;
        for(int i=0;i<size;i++){
            list.add("itemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitem-"+i);
        }
        long end=System.currentTimeMillis();
        logger.debug(">>FaceYe test list :{},cost:{}",size,end-start);

        list=new ArrayList<String>(0);

        size =100000;
        start=System.currentTimeMillis();
        for(int i=0;i<size;i++){
            list.add("itemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitem-"+i);
        }
         end=System.currentTimeMillis();
        logger.debug(">>FaceYe test list :{},cost:{}",size,end-start);

        size =1000000;
        start=System.currentTimeMillis();
        for(int i=0;i<size;i++){
            list.add("itemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitemitem-"+i);
        }
        Iterator is=list.iterator();
        end=System.currentTimeMillis();
        logger.debug(">>FaceYe test list :{},cost:{}",size,end-start);
    }

}
